<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>验证Diffing算法</title>
  <!--  引入React核心库-->
  <script src="https://unpkg.com/react@18/umd/react.development.js"></script>
  <!--  引入react-dom,用于支持React操作Dom-->
  <script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
  <!-- 引入babel，用于将jsx转为js-->
  <script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
  <script src="https://unpkg.com/prop-types@15.6.2/prop-types.js"></script>
</head>

<body>
  <!-- 准备一个容器 -->
  <div id="root"></div>
  <script type="text/babel">
    // 1.创建一个组件
    class Time extends React.Component {
      state = {
        date: new Date()
      }
      // 组件挂载完成
      componentDidMount() {
        setInterval(() => {
          this.setState({ date: new Date() })
        }, 1000)
      }
      // render调用时机：初始化渲染，状态更新之后
      render() {
        console.log('render--组件渲染');
        const { count } = this.state
        return (
          <div>
            {/*h1和input没有变化*/}
            <h1>Hello</h1>
            <input type="text" />
            {/*h2一直在变化*/}
            <h2>
              现在的时间是：{this.state.date.toTimeString()}
              {/*input没有变化*/}
              <input type="text" />
            </h2>
          </div>
        )
      }
    }
    // 2.渲染组件到页面
    const container = document.getElementById('root')
    const root = ReactDOM.createRoot(container)
    root.render(<Time />)
  </script>
</body>

</html>